package bmatch.tech.hello.dao;

import bmatch.tech.hello.dao.buider.CitySqlBuilder;
import bmatch.tech.hello.model.CommonCityCode;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Component;

@Component
@Mapper
public interface CommonCityCodeMapper {


    @SelectProvider(type = CitySqlBuilder.class, method = "buildQueryCitys")
    List<CommonCityCode> query( String name,String code);


    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table common_city_code
     *
     * @mbg.generated Tue Dec 04 21:51:28 CST 2018
     */
    @Delete({
        "delete from common_city_code",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table common_city_code
     *
     * @mbg.generated Tue Dec 04 21:51:28 CST 2018
     */
    @Insert({
        "insert into common_city_code (id, code, ",
        "name, level, parent_code, ",
        "gmt_created, gmt_modified)",
        "values (#{id,jdbcType=VARCHAR}, #{code,jdbcType=VARCHAR}, ",
        "#{name,jdbcType=VARCHAR}, #{level,jdbcType=INTEGER}, #{parentCode,jdbcType=VARCHAR}, ",
        "now(), now())"
    })
    int insert(CommonCityCode record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table common_city_code
     *
     * @mbg.generated Tue Dec 04 21:51:28 CST 2018
     */
    @Select({
        "select",
        "id, code, name, level, parent_code, gmt_created, gmt_modified",
        "from common_city_code",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="code", property="code", jdbcType=JdbcType.VARCHAR),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="level", property="level", jdbcType=JdbcType.INTEGER),
        @Result(column="parent_code", property="parentCode", jdbcType=JdbcType.VARCHAR),
        @Result(column="gmt_created", property="gmtCreated", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="gmt_modified", property="gmtModified", jdbcType=JdbcType.TIMESTAMP)
    })
    CommonCityCode selectByPrimaryKey(String id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table common_city_code
     *
     * @mbg.generated Tue Dec 04 21:51:28 CST 2018
     */
    @Select({
        "select",
        "id, code, name, level, parent_code, gmt_created, gmt_modified",
        "from common_city_code"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="code", property="code", jdbcType=JdbcType.VARCHAR),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="level", property="level", jdbcType=JdbcType.INTEGER),
        @Result(column="parent_code", property="parentCode", jdbcType=JdbcType.VARCHAR),
        @Result(column="gmt_created", property="gmtCreated", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="gmt_modified", property="gmtModified", jdbcType=JdbcType.TIMESTAMP)
    })
    List<CommonCityCode> selectAll();

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table common_city_code
     *
     * @mbg.generated Tue Dec 04 21:51:28 CST 2018
     */
    @Update({
        "update common_city_code",
        "set code = #{code,jdbcType=VARCHAR},",
          "name = #{name,jdbcType=VARCHAR},",
          "level = #{level,jdbcType=INTEGER},",
          "parent_code = #{parentCode,jdbcType=VARCHAR},",
          "gmt_modified = now()",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(CommonCityCode record);
}